package cn.qiyu5522.tk_ems.convert;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @ProjectName: tk_ems
 * @Package: cn.qiyu5522.tk_ems.convert
 * @ClassName: SexConverter
 * @Author: [Toneky]
 * @Date: 2023/2/7 22:38
 * @Version: V1.0
 **/
public class SexConverter implements Converter<Integer> {

    private static final String MAN="男";
    private static final String WOMAN="女";

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {

        return CellDataTypeEnum.STRING;
    }


    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String gender = cellData.getStringValue();
        if(MAN.equals(gender)){
            return 1;
        }else if (WOMAN.equals(gender)){
            return 0;
        }

        return null;
    }

    @Override
    public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if(integer == null){
            return new CellData<>("");
        }else if(integer == 0){
            return new CellData<>("女");
        }else if (integer == 1){
            return new CellData<>("男");
        }
        return new CellData<>("");
    }
}
